5.5. Background Procedure

Background Procedure is a procedure which will be executed while Virtual Panels is polling console. You can provide Background Procedure for each button or menu system when you activate the button or menu system by function calls bsMain.Loop(MainBackgr) or msMain.Loop(MainBackgr).

The Background Procedure may be as simple as that:

void far MainBackgr(void)
{
struct  time t;
static int sec,hund;
       // here is realized delay
 gettime(&t);
 if (sec==t.ti_sec)
   if ((t.ti_hund-hund)< 50)
     return;

     // A1 and B1 are mail boxes updated by ISR in real time
 a1 = adc2volt( A1 - ADC_ZERO );
 b1 = adc2volt( B1 - ADC_ZERO );
 Temperature = MeasureTemperature();
     // update indicators on the screen
 pindTemperature->Refresh();
 pindInphase->Refresh();
 pindOutphase->Refresh();

 sec=t.ti_sec; hund=t.ti_hund;  // for delay
 if (errCodeISR) errExit();     // exit if interrupt routine failed
}

The more complicated Background Procedure will consist of several phases. General structure of such Background Procedure may look as follows:

void far TdepBackgr(void)
{
// The code common for all phases
 .
 .
 measureA1B1T();
 updateIndicators();

 switch ( phase )
 {
  case 0:       //--- Initialization phase
       // Here the Temperature Dependence measurement
       // procedure is initialized.
       .
       .
       measInProgress=1;
       phase = 1;       // next is the phase 1
       break;
  case 1:       //--- Measurement phase
       if ( (Temperature > maxT) || (Temperature < minT) )
        phase = 10; // end measurement if temperature is out of range
       else
          { // Here measurement are going
           .
           }
       break;
  case 10:      //--- Stop measurement
       .
       .
       measInProgress=0;
       phase = 11;      // switch backgr measurement in idle mode
       fclose(dat);     // save data file if necessary
       if ( !Confirm(" Save data file ? ") )
           unlink( nameTdepDat);
       break;
  case 11:;     //--- Measurement is idle
 }//-- switch
}//------ TdepBackgr(void)